home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / infosearch.idb / usr / lib / infosearch / bin / man2html.z / man2html
Text File  |  2002-10-15  |  3KB  |  118 lines

  1. #!/usr/bin/perl
  2. #
  3. # Copyright 1996-2002, Silicon Graphics, Inc.
  4. # All Rights Reserved.
  5. #
  6. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. # the contents of this file may not be disclosed to third parties, copied or
  8. # duplicated in any form, in whole or in part, without the prior written
  9. # permission of Silicon Graphics, Inc.
  10. #
  11. # RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. # rights reserved under the Copyright Laws of the United States.
  17. #
  18. #  --------
  19. #  man2html
  20. #  --------
  21. #  filter man pages into HTML
  22. #
  23. #  Usage:
  24. #       man2html [-r <root>]  [-h <highlight_str>]  /<standard_path>/<file>
  25. #       man2html [-r <root>]  [-h <highlight_str>]  <section> <manpage>
  26. #
  27. #  requires perl5 and man2html.pl
  28. #
  29.  
  30. $| = 1;
  31.  
  32. use strict;
  33.  
  34. # globals
  35. #
  36. package InfoSearch;
  37.  
  38. $InfoSearch::COLLECTION = $ENV{'COLLECTION'};
  39. $InfoSearch::_TR        = $ENV{'TOOLROOT'};
  40. $InfoSearch::_WEB       = ($ENV{'REQUEST_METHOD'} ne '' ? 1 : 0);
  41. $InfoSearch::_DB        = 'man';
  42.  
  43. require 'man2html.pl';
  44.  
  45. &main(@ARGV);
  46. exit(0);
  47.  
  48.  
  49.  
  50. #######################################################################
  51. #
  52. # void main()
  53. #
  54. #######################################################################
  55.  
  56. sub main {
  57.  
  58.   my(@argv) = @_;
  59.   unless ($argv[0]) {
  60.         print "man2html: no arguments" if (${InfoSearch::_WEB} == 0);
  61.         return;
  62.   }
  63.  
  64.   my($fname, $man_root, $srch_str) = '';
  65.   my($i) = 0;
  66.   while($i < (@argv + 0)) {
  67.  
  68.         if ($argv[$i] eq "-h") {
  69.  
  70.            splice(@argv, $i, 1);
  71.            if( $argv[$i] ne '' ) {
  72.                $srch_str = $argv[$i];
  73.                splice(@argv, $i, 1);
  74.            }
  75.  
  76.         } elsif ($argv[$i] eq "-r") { 
  77.  
  78.            splice(@argv, $i, 1);
  79.            if( $argv[$i] ne '' ) {
  80.                $man_root = $argv[$i];
  81.                splice(@argv, $i, 1);
  82.            }
  83.  
  84.         } else {
  85.            $i++;
  86.         }
  87.   }
  88.  
  89.   # take whatever is left
  90.   #
  91.   $fname = join(' ', @argv);
  92.  
  93.   #  Set the path for security and taint checking.
  94.   #
  95.   $ENV{'PATH'} = "${InfoSearch::_TR}/usr/sbin:" .
  96.                  "${InfoSearch::_TR}/usr/bin:"  .
  97.                  "${InfoSearch::_TR}/bin:/usr/sbin:/usr/bin:/bin";
  98.  
  99.   # check (again!)
  100.   #
  101.   my($OK_CHARS) = "-a-zA-Z0-9_.*\@,:;()\ \+\/";
  102.   $fname =~ s/[^$OK_CHARS]//go;
  103.   if( $fname =~ /\.\./ || $fname =~ /^\/etc/ || $fname =~ /\&/ 
  104.       ||
  105.       $fname =~ /\;/ || $fname =~ /\|/ || $fname =~ /\,/
  106.       ||
  107.       $fname =~ /\>/ || $fname =~ /\</ ) {
  108.  
  109.       print "man2html: Illegal document access" if (${InfoSearch::_WEB} == 0);
  110.       return;
  111.   }
  112.  
  113.   &man2html($man_root, $fname, $srch_str);
  114.  
  115.   return;
  116. }
  117.  
  118.